package com.infinitus.multids.domain;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

@Component
public class CatConfigInfo {
	
	@Value("${cat.error.resolve}")
	private String resolve;
	
	@Value("${cat.error.threshold}")
	private String threshold;
	
	@Value("${cat.error.list.url}")
	private String listUrl;
	
	@Value("${cat.error.detail.url}")
	private String detailUrl;
	
	public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

	public Map<String, String> getResolveMap() {
		Map<String, String> resMap = JSON.parseObject(resolve, new TypeReference<Map<String, String>>() {});
		return resMap;
	}

	public Integer getErrorThreshold() {
		return Integer.parseInt(threshold);
	}
	
	public String getListUrl(Date date, String os, String edition) {
		return String.format(listUrl, DATE_FORMAT.format(date), os , edition);
	}
	
	public String getDetailUrl(String errorId) {
		return String.format(detailUrl, errorId);
	}

}
